﻿using System;
using System.Collections.Generic;
using System.Xml;

namespace HYRElectric.PowerSystem
{
	internal class ExportSystemXML
	{
		public ExportSystemXML(string path)
		{
			this.xmlFilePath = path;
			this.xmlDoc = new XmlDocument();
			this.xmlDoc.Load(this.xmlFilePath);
			this.xmlNode = this.xmlDoc.DocumentElement;
		}

		public List<SystemDataBlock> LoadSystemDataBlock()
		{
			List<SystemDataBlock> list = new List<SystemDataBlock>();
			foreach (object obj in this.xmlNode.ChildNodes)
			{
				XmlNode xmlNode = (XmlNode)obj;
				if (xmlNode.Name == "DataItems")
				{
					foreach (object obj2 in xmlNode.ChildNodes)
					{
						XmlNode xmlNode2 = (XmlNode)obj2;
						list.Add(new SystemDataBlock
						{
							NDataType = Convert.ToInt32(xmlNode2.Attributes["DataType"].Value),
							StrGUID = xmlNode2.Attributes["GUID"].Value,
							StrNum = xmlNode2.Attributes["Num"].Value,
							StrLoadType = xmlNode2.Attributes["LoadType"].Value,
							StrPhase = xmlNode2.Attributes["Phase"].Value,
							DPe = Convert.ToDouble(xmlNode2.Attributes["Pe"].Value),
							DUr = Convert.ToDouble(xmlNode2.Attributes["Ur"].Value),
							DKx = Convert.ToDouble(xmlNode2.Attributes["Kx"].Value),
							DCos = Convert.ToDouble(xmlNode2.Attributes["Cos"].Value),
							DIc = Convert.ToDouble(xmlNode2.Attributes["Ic"].Value),
							StrWireType = xmlNode2.Attributes["WireType"].Value,
							NWireNum = Convert.ToUInt16(xmlNode2.Attributes["WireNum"].Value),
							StrLaying = xmlNode2.Attributes["Laying"].Value,
							DWireS = Convert.ToDouble(xmlNode2.Attributes["WireS"].Value),
							StrPipeType = xmlNode2.Attributes["PipeType"].Value,
							DPipeDia = Convert.ToDouble(xmlNode2.Attributes["PipeDia"].Value),
							StrSwitchName = xmlNode2.Attributes["SwitchName"].Value,
							StrSwitchType = xmlNode2.Attributes["SwitchType"].Value,
							StrSwitchSpec = xmlNode2.Attributes["SwitchSpec"].Value,
							StrParentGUID = xmlNode2.Attributes["ParentGUID"].Value,
							Prefix = xmlNode2.Attributes["Prefix"].Value
						});
					}
				}
			}
			return list;
		}

		public SystemGraphSet LoadCSystemGraphSet(int scale)
		{
			SystemGraphSet systemGraphSet = new SystemGraphSet();
			XmlNode xmlNode = this.xmlNode.ChildNodes[0];
			if (xmlNode.Name == "HYSystemGrapSet")
			{
				foreach (object obj in xmlNode.ChildNodes)
				{
					XmlNode xmlNode2 = (XmlNode)obj;
					if (xmlNode2.Name == "InLine")
					{
						systemGraphSet.InLine = Convert.ToInt32(xmlNode2.Attributes["InLine"].Value) * scale;
						systemGraphSet.InLink = Convert.ToInt32(xmlNode2.Attributes["InLink"].Value) * scale;
					}
					else if (xmlNode2.Name == "SystemLoop")
					{
						systemGraphSet.OutLine = Convert.ToInt32(xmlNode2.Attributes["OutLine"].Value) * scale;
						systemGraphSet.OutLink = Convert.ToInt32(xmlNode2.Attributes["OutLink"].Value) * scale;
						systemGraphSet.LoopSpace = Convert.ToInt32(xmlNode2.Attributes["LoopSpace"].Value) * scale;
					}
					else if (xmlNode2.Name == "Other")
					{
						systemGraphSet.BusWidth = Convert.ToDouble(xmlNode2.Attributes["BusWidth"].Value);
						systemGraphSet.WireWidth = Convert.ToDouble(xmlNode2.Attributes["WireWidth"].Value);
						systemGraphSet.TextHeight = Convert.ToDouble(xmlNode2.Attributes["TextHeight"].Value);
						systemGraphSet.Vector = Convert.ToInt32(xmlNode2.Attributes["Vector"].Value);
					}
				}
			}
			return systemGraphSet;
		}

		private XmlDocument xmlDoc;

		private XmlNode xmlNode;

		private string xmlFilePath;
	}
}
